//
//  SDEditPersonInfoController.m
//  SuperDoctor
//
//  Created by fdq on 16/7/11.
//  Copyright © 2016年 SD. All rights reserved.
//

#import "SDEditPersonInfoController.h"

@interface SDEditPersonInfoController ()<UITextViewDelegate>

@property (nonatomic,weak)UITextView * tv_text;

@end

@implementation SDEditPersonInfoController

- (void)viewDidLoad {
    [super viewDidLoad];

	self.view.backgroundColor = [UIColor whiteColor];
	
	[self setupUI];


}

- (void)setupUI{
	
	
	//添加输入框
	UITextView * tv_text = [[UITextView alloc]init];
	
	self.tv_text = tv_text;
	
	tv_text.delegate = self;
	
	tv_text.text = self.model.information;
	
	tv_text.font = [UIFont systemFontOfSize:17];
	
	tv_text.backgroundColor = [UIColor lightGrayColor];
	
	[self.view addSubview:tv_text];
	
	[tv_text mas_makeConstraints:^(MASConstraintMaker *make) {
	
		make.left.mas_offset(5);
		
		make.right.mas_offset(-5);
		
		make.top.mas_offset(25);
		
		make.bottom.mas_equalTo(self.view.mas_centerY);
	}];

	
	//取消按钮
	
	UIButton * cancelBtn = [[UIButton alloc]init];
	
	[cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
	
	[cancelBtn setBackgroundColor:kThemeColor];
	
	cancelBtn.layer.cornerRadius = 5;
	
	cancelBtn.layer.masksToBounds = YES;
	
	[self.view addSubview:cancelBtn];
	
	[cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		
		make.left.mas_equalTo(10);
		
		make.right.mas_equalTo(self.view.mas_centerX).offset(-10);
		
		make.top.mas_equalTo(tv_text.mas_bottom).offset(10);
		
	}];
	
	
	//保存按钮
	UIButton * saveBtn = [[UIButton alloc]init];
	
	[saveBtn setTitle:@"保存" forState:UIControlStateNormal];
	
	[saveBtn setBackgroundColor:kThemeColor];
	
	[self.view addSubview:saveBtn];
	
	saveBtn.layer.cornerRadius = 5;
	
	saveBtn.layer.masksToBounds = YES;
	
	[saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		
		make.left.mas_equalTo(cancelBtn.mas_right).offset(10);
		
		make.right.offset(-10);
		
		make.top.mas_equalTo(tv_text.mas_bottom).offset(10);
		
	}];
	
	//监听取消按钮事件
	[cancelBtn addTarget:self action:@selector(clickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
	//监听保存按钮事件
	[saveBtn addTarget:self action:@selector(clickSaveBtn) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - delegate
- (void)textViewDidEndEditing:(UITextView *)textView{
	
	self.model.information = textView.text;
	
	if (self.textBlock) {
		
		self.textBlock();
	}
}


//保存按钮监听方法
- (void)clickSaveBtn{
	
	[self dismissViewControllerAnimated:YES completion:nil];
}

//取消按钮监听方法
- (void)clickCancelBtn{
	
	[self dismissViewControllerAnimated:YES completion:nil];

}

@end
